<template>
  <div class="identi" set>
    <!-- 未认证 -->
    <form class="layui-form zfb-set">
      <div class="layui-form-item">
        <label class="layui-form-label">支付宝账号</label>
        <div class="layui-input-block">
          <input type="text" v-model="accountNo" name="name" class="layui-input" placeholder="请输入您本人的支付宝账号/邮箱/手机号">
        </div>
      </div>
      <button @click="saveEvent()" type="button">保存</button>
    </form>
  </div>
</template>
<script>
import * as api from '@/service/api'
export default {
  data () {
    return {
      loading: false,
      walletData: {},
      accountNo: ''
    }
  },
  created () {
    this.getWallet()
  },
  methods: {
    async getWallet () {
      let res = await api.getWallet()
      this.walletData = res.data
      this.accountNo = this.walletData.accountNo
    },
    saveEvent () {
      if (!this.accountNo) {
        window.layer.msg('请输入支付宝账号！', {
          icon: 2
        })
        return false
      }
      if (this.walletData.accountNo) {
        this.updateWithdrawalAccount()
      } else {
        this.saveWithdrawalAccount()
      }
    },
    async saveWithdrawalAccount () {
      await api.saveWithdrawalAccount({
        accountNo: this.accountNo
      })
      window.layer.msg('操作成功')
    },
    async updateWithdrawalAccount () {
      await api.updateWithdrawalAccount({
        accountNo: this.accountNo
      })
      window.layer.msg('操作成功')
    }
  }
}
</script>
